<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Tag Search</title>
<link
	href="./../css/jquery-ui.css"
	rel="stylesheet" type="text/css" />
<script
	src="./../js/jquery.min.js"></script>
<script
	src="./../js/jquery-ui.min.js"></script>


<script type="text/javascript">
	$(document).ready(function() {
		$("input#autocomplete").autocomplete({
			source : "/tagbasedchat/searchResult"
		});
	});
	
	function submitSearch(){
		window.open("/tagbasedchat/chat?searchText="+document.getElementById("autocomplete").value,'mywin',
		'left=20,top=20,width=500,height=500,toolbar=1,resizable=0');
		
	}

	function insertTag(txt) {
		//alert("calling ");
		var xmlhttp;
		if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
			xmlhttp = new XMLHttpRequest();
		} else {// code for IE6, IE5
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
		xmlhttp.onreadystatechange = function() {
			if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
				

			}
		}
		xmlhttp.open("GET", "/tagbasedchat/searchResult?addTag="
				+ document.getElementById("tags").value, true);
		xmlhttp.send();
	}
	
	function forMe(){
		var xmlhttp;
		if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
			xmlhttp = new XMLHttpRequest();
		} else {// code for IE6, IE5
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
		xmlhttp.onreadystatechange = function() {
			if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
				document.getElementById("toMeDiv").innerHTML = xmlhttp.responseText;
				forMe();
			}
		}
		xmlhttp.open("GET", "/tagbasedchat/MyChat", true);
		xmlhttp.send();
		
		
		
	}
</script>


</head>
<body onload="forMe();">
<table border="1">

	<tr>
		<td>search:</td>

		<td><input id="autocomplete" /></td>
		<td><input type="button" onclick="submitSearch()" /></td>
	</tr>
	<tr>
		<td><input id="tags" /></td>
		<td><input type="button" onclick="insertTag()" /></td>
	</tr>
</table>
<div id="toMeDiv">

</div>
</body>
</html>